package com.myproject.mall.announcement.controller;

import com.myproject.mall.announcement.service.IAnnouncementService;
import com.myproject.mall.common.result.HttpResult;
import com.myproject.mall.domain.entity.Announcement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "公告接口")
@RestController
@RequestMapping("/api/announcement")
@RequiredArgsConstructor
public class AnnouncementController {
    private final IAnnouncementService announcementService;

    @RequestMapping("/get/all")
    public HttpResult<List<Announcement>> getAll() {
        return HttpResult.success(announcementService.getAll());
    }

    @GetMapping("get/status/{status}")
    public HttpResult<List<Announcement>> getByStatus(@PathVariable("status") Integer status) {
        return HttpResult.success(announcementService.getByStatus(status));
    }

    @PostMapping("/add")
    public HttpResult<Void> add(@RequestBody Announcement announcement) {
        announcementService.addAnnouncement(announcement);
        return HttpResult.success();
    }

    @PostMapping("/update")
    public HttpResult<Void> update(@RequestBody Announcement announcement) {
        announcementService.updateAnnouncement(announcement);
        return HttpResult.success();
    }
}
